package com.shijunhao.graduation.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author: shijunhao
 * @date: 2022/3/2 17:10
 * @description:
 */
//配置类
@Configuration
//开启Swagger
@EnableSwagger2
public class SwaggerConfig {

    //返回Docket对象，一个docket为一个组
    @Bean
    public Docket getDocket(){
        //这个是作用于描述信息部分，就是api文档的头部介绍信息
        ApiInfo apiInfo = new ApiInfo(
                //描述当前组别的title
                "毕业设计",
                //当前组的description
                "API",
                //version
                "0.0.1",
                "",
                //作者链接
                new Contact("施俊豪", "", "shijunhao610@163.com"),
                //desc
                "",
                "",
                new ArrayList());

        //这个是重点
        return new Docket(DocumentationType.SWAGGER_2)
                //设置apiInfo
                .apiInfo(apiInfo)
                //设置组别名称
                .groupName("施俊豪")
                // 设置哪些接口暴露给Swagger展示
                .select()
                // 扫描指定包中的swagger注解
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                // 扫描所有 .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}